package com.wb3.meta.api.core.controller;

import com.github.binarywang.wxpay.exception.WxPayException;
import com.wb3.meta.api.core.service.GoodsInfoService;
import com.wb3.meta.api.core.service.GoodsOrdersService;
import com.wb3.meta.api.core.vo.ReqGoodsInfoVo;
import com.wb3.meta.api.core.vo.ReqGoodsOrdersVo;
import com.wb3.meta.common.annotation.NoPermission;
import com.wb3.meta.common.annotation.RequireAuth;
import com.wb3.meta.common.authentication.RequestHolder;
import com.wb3.meta.common.plugin.BaseResultController;
import com.wb3.meta.common.pojo.ResultT;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.NoSuchAlgorithmException;

@RestController
@Api(tags = "商城-订单相关接口")
@RequestMapping("base/goods/orders")
public class GoodsOrdersController extends BaseResultController<ReqGoodsOrdersVo> {

    @Autowired
    private GoodsOrdersService goodsOrdersService;

    @Autowired
    private GoodsInfoService goodsInfoService;

    /**
     * 列表接口
     *
     * @param reqGoodsOrdersVo fd
     */
    @RequireAuth
    @Override
    @ApiOperation("列表接口")
    @GetMapping("list")
    public ResultT list(ReqGoodsOrdersVo reqGoodsOrdersVo) {
        reqGoodsOrdersVo.setUserId(RequestHolder.getUserId());
        return goodsOrdersService.getModelMapPage(reqGoodsOrdersVo);
    }


    /**
     * 明细接口
     *
     * @param reqGoodsOrdersVo
     */
    @RequireAuth
    @Override
    @ApiOperation("详情接口")
    @GetMapping("detail")
    public ResultT detail(ReqGoodsOrdersVo reqGoodsOrdersVo) {
        return goodsOrdersService.getResModelMapByConditions(reqGoodsOrdersVo);
    }

    /**
     * 新增or更新接口
     *
     * @param reqGoodsOrdersVo
     */
    @NoPermission
    @Override
    @ApiOperation("更新接口")
    @PostMapping("update")
    public ResultT saveOrUpdate(@RequestBody ReqGoodsOrdersVo reqGoodsOrdersVo) {
        return goodsOrdersService.saveOrUpdate(reqGoodsOrdersVo);
    }

    /**
     * 删除接口
     *
     * @param reqGoodsOrdersVo
     */
    @NoPermission
    @Override
    @ApiOperation("删除接口")
    @PostMapping("delete")
    public ResultT delete(@RequestBody ReqGoodsOrdersVo reqGoodsOrdersVo) {
        return goodsOrdersService.delete(reqGoodsOrdersVo);
    }


    @RequireAuth
    @ApiOperation("创建订单")
    @PostMapping("create")
    public ResultT createOrder(@RequestBody ReqGoodsOrdersVo reqGoodsOrdersVo) {
        return goodsOrdersService.createOrder(reqGoodsOrdersVo);
    }
    @RequireAuth
    @ApiOperation(value = "原生下单")
    @PostMapping("/native/create")
    public ResultT createNativeOrder(@RequestBody ReqGoodsOrdersVo reqGoodsOrdersVo)  {
        return goodsInfoService.createNativeOrder(reqGoodsOrdersVo);
    }



    @RequireAuth
    @ApiOperation("崽崽续费")
    @PostMapping("toys/renewal")
    public ResultT createOrder(@RequestBody ReqGoodsInfoVo reqGoodsInfoVo) {
        return goodsOrdersService.toysRenewal(reqGoodsInfoVo);
    }

    @ApiOperation("关闭订单接口")
    @PostMapping("cancle")
    public ResultT cancleOrder(@RequestBody ReqGoodsOrdersVo reqGoodsOrdersVo) {
        return goodsOrdersService.cancleOrder(reqGoodsOrdersVo);
    }

}
